package com.springboot.service.impl;

import com.springboot.mapper.*;
import com.springboot.model.*;
import com.springboot.service.UserLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 用户登录、注册、忘记密码接口实现类
 */
@Service
public class UserLoginServiceImpl implements UserLoginService {

    @Autowired
    private UserLoginFormMapper userLoginFormMapper;

    @Autowired
    private DoctorInfoFormMapper doctorInfoFormMapper;

    @Autowired
    private ClinicFormMapper clinicFormMapper;

    @Autowired
    private DoctorFieldFormMapper doctorFieldFormMapper;

    @Autowired
    private AuthenticationMapper authenticationMapper;

    @Autowired
    private NavigationRecordMapper navigationRecordMapper;

    //通过手机号码查找用户
    @Override
    public UserLoginForm findUserByTel(String tel)
    {
        UserLoginForm userLoginForm = userLoginFormMapper.selectByTel(tel);
        return userLoginForm;
    }

    //通过用户id查找用户
    @Override
    public UserLoginForm findUserById(Integer userId)
    {
        UserLoginForm userLoginForm = userLoginFormMapper.selectByPrimaryKey(userId);
        return userLoginForm;
    }

    //插入数据到用户信息表中
    @Override
    public int insertUserForm(UserLoginForm userLoginForm)
    {
        return userLoginFormMapper.insert(userLoginForm);
    }

    //更新用户表中的密码
    @Override
    public int updatePassword(UserLoginForm userLoginForm)
    {
        return userLoginFormMapper.updateByPrimaryKey(userLoginForm);
    }

    //通过医生id插入数据到医生信息表
    @Override
    public int insertById(DoctorInfoForm doctorInfoForm)
    {
        return doctorInfoFormMapper.insertSelective(doctorInfoForm);
    }

    //插入数据到诊所信息表中
    @Override
    public int insertClinic(ClinicForm clinicForm)
    {
        return clinicFormMapper.insertSelective(clinicForm);
    }

    //通过诊所名称查找诊所信息
    @Override
    public ClinicForm findClinic(String name)
    {
        return clinicFormMapper.selectByname(name);
    }

    //插入数据到医生领域表中
    @Override
    public int insertDoctorField(DoctorFieldForm doctorFieldForm)
    {
        return doctorFieldFormMapper.insert(doctorFieldForm);
    }

    //通过诊所名称查找诊所记录
    @Override
    public ClinicForm findByClinicName(String clinicName)
    {
        return clinicFormMapper.selectByname(clinicName);
    }

    //插入数据到认证表中
    @Override
    public int insertAuthentication(Authentication authentication)
    {
        return authenticationMapper.insertSelective(authentication);
    }

    //【陈佳伟】：更新用户登录表
    @Override
    public int updateUserLoginForm(UserLoginForm userLoginForm)
    {
        int a=userLoginFormMapper.updateByPrimaryKeySelective(userLoginForm);
        return a;
    }

    //更新认证表
    @Override
    public int updateAuthentication(Authentication authentication)
    {
        return authenticationMapper.updateByPrimaryKeySelective(authentication);
    }

    //通过医生id查找Authentication
    @Override
    public Authentication findAuthenticationById(Integer userId)
    {
        return authenticationMapper.selectByPrimaryKey(userId);
    }

    @Override
    public  int insertNavigation(NavigationRecord navigationRecord)
    {
        int a=0;
        try {
            a = navigationRecordMapper.insertSelective(navigationRecord);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            System.out.println("插入tablebar错误");
        }
        return a;
    }
}
